﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

namespace SGS.Cards
{
    [Serializable()]
    public class CardCollection : LinkedList<Card>// , ISerializable
    {
        public CardCollection()
        {
        }

        public CardCollection(IEnumerable<Card> cards)
            : base(cards)
        {
        }

        protected CardCollection(SerializationInfo info, StreamingContext context) :
            base(info, context)
        {
        }

        public void PushToStart(IEnumerable<Card> cards)
        {
            foreach (var c in cards)
            {
                this.AddFirst(c);
            }
        }

        public void PushToEnd(IEnumerable<Card> cards)
        {
            foreach (var c in cards)
            {
                this.AddLast(c);
            }
        }

        public void Shuffle()
        {
            lock (this)
            {
                var dummy = this.ToList();
                this.Clear();

                var result = SGS.Utility.Common.RandomSort(dummy);
                PushToStart(result);
            }
        }

        public Card PopFirst()
        {
            if (this.Count == 0)
            {
                return null;
            }
            else
            {
                var dummy = this.First.Value;
                this.RemoveFirst();
                return dummy;
            }
        }

        public void RemoveCard(IEnumerable<Card> cards)
        {
            foreach (var c in cards)
            {
                this.Remove(c);
            }
        }

        public bool Has(params Card[] cards)
        {
            if (cards.Length == 0)
            {
                return true;
            }

            foreach (var c in cards)
            {
                if (!this.Contains(c))
                {
                    return false;
                }
            }
            return true;
        }

        //public void GetObjectData(SerializationInfo info, StreamingContext context)
        //{
        //    base.GetObjectData(info, context);
        //}
    }
}
